package com.example.projecth.projecthealth;

import com.example.projecth.R;

import android.app.Fragment;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.TextView;

public class MyOnedayFragment extends Fragment {

	private CalendarMonthView monthView;
	private CalendarMonthAdapter monthViewAdapter;
	private TextView monthText;
	private int curYear;
	private int curMonth;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		View view = inflater.inflate(R.layout.myoneday_calendar, container, false);
		
		monthView = (CalendarMonthView) view.findViewById(R.id.monthView);
		monthViewAdapter = new CalendarMonthAdapter(getActivity());
		monthView.setAdapter(monthViewAdapter);
		
		monthView.setOnDataSelectionListener(new OnDataSelectionListener() { 
            public void onDataSelected(AdapterView parent, View v, int position, long id) { 
                // 현재 선택한 일자 정보 표시 
                MonthItem curItem = (MonthItem) monthViewAdapter.getItem(position); 
                int day = curItem.getDay(); 
  
                Log.d("CalendarMonthViewActivity", "Selected : " + day); 
  
            } 
        });
		
		monthText = (TextView) view.findViewById(R.id.monthText); 
//		setMonthText(); 
  
        // 이전 월로 넘어가는 이벤트 처리 
        Button monthPrevious = (Button) view.findViewById(R.id.monthPrevious); 
        monthPrevious.setOnClickListener(new OnClickListener() { 
            public void onClick(View v) { 
                monthViewAdapter.setPreviousMonth(); 
                monthViewAdapter.notifyDataSetChanged(); 
  
                setMonthText(); 
            } 
        }); 
        setMonthText();
        // 다음 월로 넘어가는 이벤트 처리 
        Button monthNext = (Button) view.findViewById(R.id.monthNext); 
        monthNext.setOnClickListener(new OnClickListener() { 
            public void onClick(View v) { 
                monthViewAdapter.setNextMonth(); 
                monthViewAdapter.notifyDataSetChanged(); 
  
                setMonthText(); 
            } 
        }); 
        setMonthText(); 
		return view;
	}
	
	/** 
     * 월 표시 텍스트 설정 
     */
    private void setMonthText() { 
        curYear = monthViewAdapter.getCurYear(); 
        curMonth = monthViewAdapter.getCurMonth(); 
  
        monthText.setText(curYear + "년 " + (curMonth+1) + "월"); 
    } 
    
}
